<#escape x as (x)!"">
package ${basePackage}.${plate}.${modulePackage}.controller;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import ${basePackage}.common.annotation.SysLog;
import ${basePackage}.common.excel.Column;
import ${basePackage}.common.excel.ExcelExport;

import ${basePackage}.utils.xss.XssHttpServletRequestWrapper;
import com.alibaba.fastjson.JSON;
import ${basePackage}.mgt.sys.controller.AbstractController;
import ${basePackage}.entity.${modulePackage}.${className}Entity;
import ${basePackage}.${platPackage}.${modulePackage}.service.${className}Service;
import ${basePackage}.utils.Query;
import com.github.pagehelper.Page;
import ${basePackage}.result.Result;
import ${basePackage}.result.ResultGenerator;
import ${basePackage}.utils.CompareUtils;
import ${basePackage}.utils.FormatUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * ${comments}
 * 
 * @author ${author}
 * @email ${email}
 * @date ${datetime}
 */
 @SuppressWarnings("rawtypes")
@RestController
@Api("${comments}")
@RequestMapping("${pathName}")
public class ${className}Controller extends AbstractController{
	@Autowired
	private ${className}Service ${classname}Service;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@ApiOperation(value = "列表", notes = "说明")
	@RequiresPermissions("${pathName}:list")
	public Result list(@RequestBody Map params){

		// 查询列表数据
		Query query = new Query(params);
		Page<${className}Entity> page = ${classname}Service.queryPageList(query);
		return ResultGenerator.successPage(page);
	}
	
	
	/**
	 * 信息
	 */
	@GetMapping("/info/{${pk.attrname}}")
	@ApiOperation(value = "信息", notes = "说明")
	@RequiresPermissions("${pathName}:info")
	public Result info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){
		${className}Entity ${classname} = ${classname}Service.queryObject(${pk.attrname});
		
		return ResultGenerator.successData(${classname});
	}
	
	/**
	 * 保存
	 */
	@SysLog("新增${comments}")
	@PostMapping("/save")
	@ApiOperation(value = "保存", notes = "说明")
	@RequiresPermissions("${pathName}:save")
	public Result save(@RequestBody ${className}Entity ${classname}){
	
		${classname}Service.save(${classname});
		
		//处理日志
		Map<String,String> cmap = new HashMap<String,String>();
	<#if columns??>
		<#list columns as column>
		  <#if !column.noinput>
		     cmap.put("${column.attrname}","${column.shortComments}");
		  </#if>
		</#list>
	</#if>
		String remark = CompareUtils.getObjectRemark(${classname}, cmap);
		return ResultGenerator.success("保存成功").setRemark(remark);
	}
	
	/**
	 * 修改
	 */
	@SysLog("修改${comments}")
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "说明")
	@RequiresPermissions("${pathName}:update")
	public Result update(@RequestBody ${className}Entity ${classname}){
	
		${className}Entity ${classname}1 = ${classname}Service.queryObject(${classname}.get${pk.attrName}());
	
		${classname}Service.update(${classname});
		
		//处理日志
		Map<String,String> cmap = new HashMap<String,String>();
		
	<#if columns??>
		<#list columns as column>
		  <#if !column.noinput>
		     cmap.put("${column.attrname}","${column.shortComments}");
		  </#if>
		</#list>
	</#if>
	
		String remark = CompareUtils.getTwoObjectRemark(${classname}1, ${classname}, cmap);
	
		return ResultGenerator.success("修改成功").setRemark(remark);
	}
	
	/**
	 * 删除
	 */
	@SysLog("删除${comments}")
	@GetMapping("/delete/{${pk.attrname}}")
	@ApiOperation(value = "删除", notes = "说明")
	@RequiresPermissions("${pathName}:delete")
	public Result delete(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){
	
	    	if (${pk.attrname} == null) {
			return ResultGenerator.fail("缺少参数");
		}
	
		${className}Entity ${classname} = ${classname}Service.queryObject(${pk.attrname});
	
		${classname}Service.delete(${pk.attrname});
		
		//处理日志
		Map<String,String> cmap = new HashMap<String,String>();
	<#if columns??>
		<#list columns as column>
		  <#if !column.noinput>
		     cmap.put("${column.attrname}","${column.shortComments}");
		  </#if>
		</#list>
	</#if>
		String remark = CompareUtils.getObjectRemark(${classname}, cmap);
		return ResultGenerator.success("删除成功").setRemark(remark);
	}
	
	/**
	 * 批量删除
	 */
	@SysLog("批量删除${comments}")
	@PostMapping("/deletes")
	@ApiOperation(value = "删除", notes = "说明")
	@RequiresPermissions("${pathName}:delete")
	public Result deletes(@RequestBody ${pk.attrType}[] ${pk.attrname}s){
	
		${classname}Service.deleteBatch(${pk.attrname}s);
		
		return ResultGenerator.success("删除成功");
	}
	
	@RequestMapping("/download")
	@ApiOperation(value = "下载", notes = "说明")
	@RequiresPermissions("${pathName}:list")
	public void download(HttpServletRequest request, HttpServletResponse response) {

		HttpServletRequest orgRequest = XssHttpServletRequestWrapper.getOrgRequest(request);
		
		String query = orgRequest.getParameter("query");

		HashMap querymap = JSON.parseObject(query, HashMap.class);

		List<${className}Entity> list = ${classname}Service.queryList(querymap);

		if (list != null && list.size() > 0) {
			Map map = new HashMap();

	<#if columns??>
		<#list columns as column>
		<#if column.map??>
            <#if column.attrType="String">
               Map<String, String> ${column.attrname}Map = new HashMap<String, String>();

                <#list column.map?keys as key>
                ${column.attrname}Map.put("${key}", "${column.map[key]}");
                </#list>

            <#else>
               Map<Integer, String> ${column.attrname}Map = new HashMap<Integer, String>();

                <#list column.map?keys as key>
                ${column.attrname}Map.put(${key}, "${column.map[key]}");
                </#list>
            </#if>
            map.put("${column.attrname}Map", ${column.attrname}Map);
		</#if>
		</#list>
	</#if>

			List<Column> clist = new ArrayList();
			Column cloumn = null;

	<#if columns??>
		<#list columns as column>
		    <#if column.map??>
            cloumn = new Column("${column.shortComments}", "${column.attrname}", 2);
			clist.add(cloumn);
			<#else>
            cloumn = new Column("${column.shortComments}", "${column.attrname}", 1);
			clist.add(cloumn);
			</#if>
		</#list>
	</#if>
			try {
				ExcelExport export = exportList(list, clist, map);
				if (export != null) {
					this.downExcel(export, response);
					//this.downzip(export, response);
				}

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
</#escape>